package cn.example.demo.modules.sys.model.entity;

import cn.example.demo.common.model.tree.factory.AbstractTreeNode;
import cn.example.demo.common.tools.obj.reflect.Immutable;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import java.util.List;

/**
 * <p>
 * 系统部门-数据结构
 * </p>
 *
 * @author Lizuxian
 * @create 2021-03-24 16:03
 */
@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
public class SysDepartment implements AbstractTreeNode<SysDepartment> {
    @Immutable
    @TableId(type = IdType.AUTO)
    private Integer node;   // 主键自增

    @Immutable
    @Column(nullable = false)
    private Integer parentNode;

    @Column(nullable = false, columnDefinition = "boolean")
    private Boolean isNode;

    @Column(nullable = false, columnDefinition = "boolean")
    private Boolean isDirectory;

    @Column(length = 50, nullable = false)
    private String deptName;   // 部门名称

    @Column(nullable = false)
    @TableField(value = "`rank`")
    private Integer rank;   // 同级节点次序

    @TableField(exist = false)
    private List<SysDepartment> children;

    @TableField(exist = false)
    private List<SysDepartment> parents;

    @Override
    public String getNodeId() {
        return this.node.toString();
    }

    @Override
    public String getNodeParentId() {
        return this.parentNode.toString();
    }

    @Override
    public void setChildrenNodes(List<SysDepartment> childrenNodes) {
        this.children = childrenNodes;
    }

    @Override
    public void setParentsNodes(List<SysDepartment> parentsNodes) {
        this.parents = parentsNodes;
    }
}
